package com.example.demo.sensitive.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.sensitive.entity.SensitiveWord;
import lombok.Data;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * @ClassName SensitiveWordMapper
 * @Description 敏感词数据访问层
 * @Author System
 * @Date 2025/9/19
 **/
@Mapper
public interface SensitiveWordMapper extends BaseMapper<SensitiveWord> {

    /**
     * 分页查询敏感词
     */
    Page<SensitiveWord> selectPageWithCondition(Page<SensitiveWord> page, 
                                               @Param("category") String category,
                                               @Param("status") Integer status,
                                               @Param("keyword") String keyword);

    /**
     * 根据分类查询敏感词
     */
    List<SensitiveWord> selectByCategory(@Param("category") String category);

    /**
     * 根据ID列表查询敏感词
     */
    List<SensitiveWord> selectByIds(@Param("ids") List<Long> ids);

    /**
     * 根据关键词模糊查询
     */
    List<SensitiveWord> selectByWordLike(@Param("word") String word);

    /**
     * 查询所有启用的敏感词
     */
    List<SensitiveWord> selectEnabledWords();

    /**
     * 统计各分类的敏感词数量
     */
    List<CategoryCount> countByCategory();

    /**
     * 批量插入敏感词
     */
    int batchInsert(@Param("list") List<SensitiveWord> list);

    /**
     * 批量更新状态
     */
    int batchUpdateStatus(@Param("ids") List<Long> ids, @Param("status") Integer status);

    /**
     * 分类统计内部类
     */
    @Data
    class CategoryCount {
        private String category;
        private Integer count;
    }
}
